package view;

public class Menu {
	
	// INSTANCE VARIABLES
	
	private String text;
	private int exitCode;
	
	// CONSTRUCTORS
	
	public Menu(String... optionValues) {
		this.exitCode = optionValues.length + 1;
		this.text = this.buildMenuText(optionValues);
	}
	
	// PROPERTIES
	
	/** Returns the value entered by the user */
	public int getSelection(){
		return IO.inputDialogInt(this.text, "Menu");
	}
	
	/** Returns the exit code which quits the application */
	public int getExitCode(){
		return this.exitCode;
	}
	
	// METHODS
	
	/** Takes a number of strings and formats them to appear as a menu */
	private String buildMenuText(String... optionValues) {
		
		String s = new String();
		
		// Build menu text
		for (int i = 0; i < optionValues.length; i++) {
			s += (i + 1) + "." + optionValues[i] + "\n";
		}
		
		// Add exit code
		s += this.exitCode + "." + "Quit" + "\n\n";
		s += "Choose your destiny (1-" + this.exitCode + ")";
		
		// Return menu text
		return s; 
	}
}